'use strict'

const nunjucks = require('nunjucks')

function createEnv(path,opts){
    let autoescape = opts.autoescape === undefined ? true : opts.autoescape
    let noCache = opts.noCache || false
    let watch = opts.watch || false
    let throwOnUndefined = opts.throwOnUndefined || false

    let env = new nunjucks.Environment(
        new nunjucks.FileSystemLoader('views',{
            noCache:noCache,
            watch:watch
        }),{
            autoescape:autoescape,
            throwOnUndefined:throwOnUndefined
        }
    )

    if(opts.fileters){
        for(var f in opts.fileters){
            env.addFilter(f,opts.fileters[f])
        }
    }
}

var env = createEnv('views',{
    watch:true,
    fileters:{
        hex:function(n){
            return '0x' + n.toString(16)
        }
    }
})

var s = env.rander('hello.html',{name:'小明'})
console.log(s);